<template>
   <el-form inline ref="postForm" :model="form" class="filter" label-width="100px">
    <el-form-item label="赠送条数：" prop="name">
      <el-col :span="5">
        <el-input-number v-model="form.giveAsk" :min="0" controls-position="right" size="large"/>
      </el-col>
    </el-form-item>
   </el-form>
   <div class="footer">
      <el-button type="primary" @click="handleSave(postForm)">确定</el-button>
    </div>
</template>
<script lang="ts" setup>
import { ref, onMounted } from 'vue'
import { useCommonStore } from '@/stores/common'
import {SettingSave} from '@/api/common'
import {ElForm, ElMessage} from 'element-plus'
const commonStore  = useCommonStore()
const form = ref<SiteSetting>(commonStore.setting)
type FormInstance = InstanceType<typeof ElForm>
const postForm = ref<FormInstance>()
const handleSave  = (formEl: FormInstance | undefined): void => {
    if (!formEl) return
    formEl.validate((valid: boolean) => {
      if (valid) {
        SettingSave(form.value).then(() => {
          ElMessage.success('保存成功')
        })
      } else {
        ElMessage.error('请检查表单')
        return false
      }
    })
}
onMounted(() => {
  if(!commonStore.setting.fileDomain)
  commonStore.getSetting().then((res:SiteSetting) => {
    form.value = res
  })
})
</script>
<style lang="scss" scoped>
  @import '@/assets/styles/mixin.scss';
  @import '@/assets/styles/formPage.scss';
</style>